//window.localStorage.isWeiXin
import cTitle from "components/title";
import popUp from "./components/pop-up";
export default {
  //name: 'login',
  data() {
    return {
      show: false, //底部弹窗
      dataList: '',
      openPlatformAgreement: false,
      userAgreement: '', //用户协议
      platformAgreement: '', //平台协议
      wechat_login_mode: false,
      showEmail:false,
    };
  },
  activated() {
    this.getData()
  },
  methods: {
    confirm() {
      this.show = false
    },
    openPopUp(e) { //弹出下拉框
      this.$refs.popUp.checkShow()
      this.$refs.popUp.stateChanges(e)
      if(e == 'email'){
        this.$refs.popUp.email = '';
        if(this.dataList.email){
          this.$refs.popUp.email = this.dataList.email;
        }
      }
    },
    getData() {
      let that = this
      var reg = /^(\d{6})\d+(\d{4})$/;
      $http.get('member.member-info.user-info-update-page').then((response)=> {
        if (response.result == 1) {
          let basic_info = JSON.parse(localStorage.getItem("yz_basic_info"))
          this.showEmail = basic_info?.plugin_setting?.email_register?.is_open;
          that.dataList = response.data
          if(!that.fun.isTextEmpty(that.dataList.bank_card)){
            that.dataList.bank_card = that.dataList.bank_card.replace(reg, "$1******$2")
          }
          that.$refs.popUp.alipayForm.alipay = response.data?.alipay
          that.$refs.popUp.alipayForm.alipayname = response.data?.alipayname
          that.$refs.popUp.weChatForm.wechat = response.data?.wechat
          that.agreementContent()
        }
      }, function(response) {
        // error callback
      });
    },
    getMemberData() {
      $http
        .post("member.member.member-data", {
          v: 2,
          basic_info: 1
        }, " ").then(
          response => {
            if (response.result === 1) {
              this.wechat_login_mode = response.data.setting.wechat_login_mode;
            }
          });
    },
    // 退出登录
    outInfo() {
      $http.get("member.logout.index").then(
        response => {
          if (response.result == 1) {
            window.localStorage.setItem("isWxLogin", -1);
            this.$store.commit("savemodel", {});
            localStorage.setItem("token", "");
            localStorage.setItem("loginUid", "");
            window.firstLogin = 0;
            clearLoginData(); // 方法在index.html
            if (this.fun.isCPS() && this.fun.isCPSAPPI()) {
              // 聚合APP退出方法
              if (this.fun.isIosOrAndroid() === "ios") {
                toQuitIOS({
                  body: "toQuitIOS"
                });
              } else {
                toQuitAndroid();
              }
              return;
            }

            this.$dialog
              .alert({
                message: response.msg
              })
              .then(() => {
                this.$router.push(this.fun.getUrl("login"));
              })
              .catch(() => {});
          }
        },
        response => {
          console.log(response.msg);
        }
      );
    },
    // 绑定手机
    bindTel() {
      this.$router.push(
        this.fun.getUrl('editmobile', {
          num: this.dataList.mobile,
          myparent: this,
        }, {
          is_edit: '1'
        })
      );
      sessionStorage.setItem('isset', 1);
    },
    openOpenPlatformAgreement() { //弹出用户协议弹窗
      if (this.fun.isPc()) {
        this.$router.push(this.fun.getUrl('registerAgreement'));
      } else {
        this.openPlatformAgreement = true;
      }
    },
    agreementContent() { //获取协议内容
      let that = this
      if (this.dataList.platform_agreement.status) { //平台协议
        $http.get('member.member-info.platform-agreement').then(function(response) {
          if (response.result == 1) {
            that.platformAgreement = response.data
          }
        }, function(response) {
          // error callback
        });
      }
    },
    // 银行卡
    editBank() {
      this.$router.push(this.fun.getUrl('memberBank', {}));
    },
    // 汇聚结算卡
    convergenceSettlementCard() {
      this.$router.push(this.fun.getUrl('bankCardInformation', {}));
    },
    // 收货地址管理
    address() {
      this.$router.push(this.fun.getUrl('address', {}));
    },
    // 支付密码
    paymentCode() {
      let that = this;
      $http.get('member.balance-password.is-has-password', {}, '').then(
        function(response) {
          if (response.result == 1) {
            if (response.data.is_has) {
              that.$router.push(that.fun.getUrl('balance_password', {}));
            } else {
              that.$router.push(that.fun.getUrl('set_balance_password', {}));
            }
          } else {
            that.$dialog.alert({message:response.msg});
          }
        },
        function(response) {
          that.$dialog.alert({message:response.msg});
        }
      );
    },
    //用户协议
    toUserAgreement() {
      this.$router.push(this.fun.getUrl('registration_platform_agreement', {},{show:'user'}));
    },
    // 账号注销
    memberCancel() {
      this.$router.push(this.fun.getUrl('MemberCancel', {}));
    },
    // 跳转到用户基本信息页面
    editUserInformation() {
      this.$router.push(this.fun.getUrl('userinfo', {}, {
        pageType: 'UserInformation'
      }));
    }
  },
  components: {
    cTitle,
    popUp
  }
};
